package com.ruoyi.system.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.domain.CloudBaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 用户订单对象 asset_customer_order
 *
 * @author ruoyi
 * @date 2024-12-12
 */
@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class AssetCustomerOrder extends CloudBaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 主键id
     */
    private Long id;

    /**
     * 租户ID
     */
    @Excel(name = "租户ID")
    private Long tenantId;

    /**
     * 客户id
     */
    @Excel(name = "客户id")
    private Long customerId;

    /**
     * 订单号
     */
    @Excel(name = "订单号")
    private String number;

    /**
     * 订单状态（1-待付款，2-已完成，3-已取消，4-已退款）
     * OrderStatusEnum
     */
    @Excel(name = "订单状态", readConverterExp = "1=-待付款，2-已完成，3-已取消，4-已退款")
    private Integer status;

    /**
     * 订单金额
     */
    @Excel(name = "订单金额")
    private BigDecimal totalAmount;

    /**
     * 支付时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime checkoutTime;

    /**
     * 支付方式（1-微信，2-支付宝）
     * OrderPayMethodEnum
     */
    @Excel(name = "支付方式", readConverterExp = "1=-微信，2-支付宝")
    private Integer payMethod;

    /**
     * 优惠券id
     */
    @Excel(name = "优惠券id")
    private Long voucherId;

    /**
     * 优惠金额
     */
    @Excel(name = "优惠金额")
    private BigDecimal discountAmount;

    /**
     * 订单类型（ 1-临停缴费，2-月租缴费，3-预约停车，4-代客泊车）
     * OrderTypeEnum
     */
    @Excel(name = "订单类型", readConverterExp = "1=-临停缴费，2-月租缴费，3-预约停车，4-代客泊车")
    private Integer orderType;

    /**
     * 删除标识：0-否，1-是
     */
    private Integer delFlag;

    /**
     * 订单实际金额
     *
     * @return
     */
    public BigDecimal getActualAmount() {
        BigDecimal actualAmount = totalAmount.subtract(discountAmount);
        if (BigDecimal.ZERO.compareTo(actualAmount) > 0) {
            actualAmount = BigDecimal.ZERO;
        }
        return actualAmount;
    }

}
